package com.tengju.data.infrastructure.repository.clickhouse.crm;

import com.tengju.data.domain.model.clickhouse.crm.ActivityCrowdRepository;
import com.tengju.data.domain.shared.DateUtil;
import com.tengju.data.domain.shared.JsonUtil;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.dealerclickhouse.crm.ActivityCrowdMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author chenhang
 * @Date 2022/1/8
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ActivityCrowdRepositoryImpl implements ActivityCrowdRepository {

    private final ActivityCrowdMapper activityCrowdMapper;


    @Override
    public void saveCrowdUser(Long activityId, Long crowdId, LocalDateTime insertTime, List<Long> idCodeList) {
        String insertTimeStr = DateUtil.formatLocalDateTime(DateUtil.DATE_TIME_FORMAT,insertTime);
        activityCrowdMapper.batchInsertCrowdUser(activityId,crowdId,insertTimeStr,idCodeList);
    }

    @Override
    public void syncActivityCrowdDetail(Long activityId, Long crowdId, List<Integer> limitVtnLevels) {
        LocalDateTime insertTime = LocalDateTime.now();
        String insertTimeStr = DateUtil.formatLocalDateTime(DateUtil.DATE_TIME_FORMAT,insertTime);
        activityCrowdMapper.syncActivityCrowdDetail(activityId,crowdId,limitVtnLevels,insertTimeStr);
    }

    @Override
    public void syncActivityCrowdDetailFromBehavior(Long activityId, Long crowdId) {
        LocalDateTime insertTime = LocalDateTime.now();
        String insertTimeStr = DateUtil.formatLocalDateTime(DateUtil.DATE_TIME_FORMAT,insertTime);
        activityCrowdMapper.syncActivityCrowdDetailFromBehavior(activityId,crowdId,insertTimeStr);
    }
}
